//
//  SelectView.m
//  AssistantDriving
//
//  Created by dcr on 2017/1/5.
//  Copyright © 2017年 邓兆太. All rights reserved.
//

#import "SelectView.h"

@implementation SelectView
{
    UIButton *_button;
}

- (instancetype)initWithFrame:(CGRect)frame andBtn:(UIButton *)btn{
    self = [super initWithFrame:frame];
    if(self){
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
        [self createBtn];
    }
    _button = btn;
    return self;
}

- (void)createBtn{
    for(int i = 0; i < 4; i++){
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        btn.frame = CGRectMake(self.frame.size.width/4*i+self.frame.size.width/4/2-30, self.frame.size.height-80, 60, 60);
        [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self hideView];
}

- (void)click:(UIButton *)sender{
    [_button setBackgroundImage:[sender backgroundImageForState:UIControlStateNormal] forState:UIControlStateNormal];
    [self hideView];
}

- (void)hideView{
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    }];

}

@end
